// 在vue-config.js 中加入
const isProduction = true
module.exports = {
    publicPath: './',
    // 配置webpack
    // configureWebpack: config => {
    //     if (isProduction) {
    //         // 开启分离js
    //         config.optimization = {
    //             runtimeChunk: 'single',
    //             splitChunks: {
    //                 chunks: 'all',
    //                 maxInitialRequests: Infinity,
    //                 minSize: 20000,
    //                 cacheGroups: {
    //                     vendor: {
    //                         test: /[\\/]node_modules[\\/]/,
    //                         name(module) {
    //                             // get the name. E.g. node_modules/packageName/not/this/part.js
    //                             // or node_modules/packageName
    //                             const packageName = module.context.match(/[\\/]node_modules[\\/](.*?)([\\/]|$)/)[1]
    //                             // npm package names are URL-safe, but some servers don't like @ symbols
    //                             return `npm.${packageName.replace('@', '')}`
    //                         }
    //                     }
    //                 }
    //             }
    //         };
    //     }
    // }
    chainWebpack: config => {
        if (process.env.NODE_ENV === 'production') {
            // #region 忽略生成环境打包的文件
            var externals = {
                'vue': 'Vue',
                'echarts': 'echarts'
            }
            config.externals(externals)

            // 在html文件中引入相关CDN
            const cdn = {
                js: [
                    // vue
                    'https://cdn.staticfile.org/vue/2.5.22/vue.min.js',
                    //echarts
                    'https://cdn.bootcss.com/echarts/4.6.0/echarts-en.common.js'
                ]
            }
            config.plugin('html')
                .tap(args => {
                    args[0].cdn = cdn
                    return args
                })
        }
    },

}
